package server.controller.userController;

import server.db.DBFactory;
import server.entity.User;
import server.model.factory.ModelFactory;
import server.util.InfoUtils.Info;
import server.util.MyUtils;
import server.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/setUserInfo")
public class SetUserInfoServlet extends HttpServlet {
    private static final long serialVersionUID = -4407524499418594762L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer userId = (Integer) req.getAttribute("userId");
        User user = MyUtils.convertRequest2Bean(req, User.class);
        user.setUserId(userId);
        Info info = ModelFactory.getUserInfoModel().setUserInfo(user);
        ResponseUtil.responseMessage(resp, info);
    }
}
